package behavioral.command;

import behavioral.command.base.Cotroler;
import behavioral.command.base.cmds.LightOffCmd;
import behavioral.command.base.cmds.LightOnCmd;
import behavioral.command.base.objs.Light;
import behavioral.command.dataProc.Command;
import behavioral.command.dataProc.MacroCommand;
import behavioral.command.dataProc.NetPaperProcesser;
import behavioral.command.dataProc.cmds.PaperAuthorCmd;
import behavioral.command.dataProc.cmds.PaperDateCmd;
import behavioral.command.dataProc.objs.NetPaper;

/**
 * 命令模式
 * 将一个请求封装为一个对象，使发出请求的责任和执行请求的责任分割开。
 */
public class Main {

    public static void main(String[] args) {
        Cotroler cotroler = new Cotroler();
        Light light = new Light("客厅");
        // step1 创建命令
        LightOnCmd lightOnCmd = new LightOnCmd(light);
        LightOffCmd lightOffCmd = new LightOffCmd(light);
        // step2 装载命令
        cotroler.setCommand(0, lightOnCmd, lightOffCmd);
        // step3 执行命令
        cotroler.onBtnClick(0);
        cotroler.offBtnClick(0);


        NetPaper netPaper = new NetPaper("标题1", "2021-2-11", "张三*, 李四, 王五");
        PaperAuthorCmd authorCmd = new PaperAuthorCmd(netPaper);
        PaperDateCmd dateCmd = new PaperDateCmd(netPaper);
        Command[] commands = new Command[]{authorCmd, dateCmd};

        MacroCommand macroCommand = new MacroCommand(commands); // 打包处理
        NetPaperProcesser processer = new NetPaperProcesser();
        processer.setCommand(macroCommand);
        processer.doProc();
        System.out.println(netPaper.getPaper().toString());
    }
}
